/**********************************************
 * 
 * File Name				:	common.js
 * 
 * Last Changed Date		: 	$Date: 2009-08-01 11:12:53 +0800 (星期六, 01 八月 2009) $
 * 
 * Last Changed Revision	:	$Revision: 86 $
 * 
 * Last Changed Author		:	$Author: cfanboy $
 * 
 * File Header URL			:	$HeadURL: svn://www.svnhost.cn/Busi-Building/code/branch/WebContent/js/common.js $
 * 
 * ********************************************
 */
 
/**
 * Validate the cookie is or not empty.
 * @param {} name
 * @return {Boolean}
 */
function isCookiesEmpty(name) {
	if (Cookies.getOriginalCookie(name) == "") {
		return true;
	} else {
		return false;
	}
}

/**
 * Validate and show tips of the fields that can't be null.
 * @param {} fieldName <The field id shoule be validated>
 * @param {} tips <The defined balloon tips>
 */
function validateFields(fieldName, tips){
	if (document.getElementById(fieldName).value == ''){
		tips.show();
	}else{
		tips.hide();
	}
}

function validateFieldsOnPress(fieldName){
	if(document.addEventListener){
		document.addEventListener("keypress",function(){
			if (document.getElementById(fieldName).value == ''){
				tips.show();
			}else{
				tips.hide();
			}
		}, true);
	}else{
		document.attachEvent("onkeypress",function(evt){
			if (document.getElementById(fieldName).value == ''){
				tips.show();
			}else{
				tips.hide();
			}
		});
	}
}



/**
 * Submit the form
 * @param {} action <the action will be executed>
 * @param {} form	<the form id>
 * @param {} message <if you passed, before the form submit, this message will be displayed.
 * @return {Boolean}
 */
function resubmit(action,form,message){
	var tempForm = document.getElementById(form);
	tempForm.action=action;
	var num=arguments.length;
	if(num>3){
		for(var j=3;j<arguments.length;j++){
			var node=window.document.getElementById(arguments[j]);
			var list=node.getElementsByTagName("option");
			for(var i=0;i<list.length;i++){
				list[i].selected="selected";
			}
		}
	}
	if(message.length>0){
		if(window.confirm(message)){
			tempForm.submit();
		}else
			return false;
	}else
		tempForm.submit();
	var inputList=window.document.getElementsByTagName("input");
	var selectList=window.document.getElementsByTagName("select");
	for(var i=0;i<selectList.length;i++){
			selectList[i].disabled=true;
	}
	for(var i=0;i<inputList.length;i++){
		if(inputList[i].type=='button' || inputList[i].type=='submit' || inputList[i].type == 'reset')
			inputList[i].disabled=true;
	}
}

/**
 * to determine which browse you are using and binding different event listener to different browse(IE/FF)
 * @param {} buttonName
 */
function pressKeyDown(buttonName){
	if(document.addEventListener){
		document.addEventListener("keypress",function(evt){
			if(evt.keyCode==13){
				document.getElementById(buttonName).click();
			}
		}, true);
	}else{
		document.attachEvent("onkeypress",function(evt){
			if(evt.keyCode==13){
				document.getElementById(buttonName).click();
			}
		});
	}
}

/**
 * Change the background color of displaytag when mouse over
 * @param {} tableId the displaytag id
 */
function handleDisplayTag(tableId){
	var previousClass = null;
	var table = document.getElementById(tableId);
	var tbody = table.getElementsByTagName("tbody")[0];
	if (tbody == null){
		var rows = table.getElementsByTagName("tr");
	}else{
		var rows = tbody.getElementsByTagName("tr");
	}
	for (i=0; i<rows.length; i++){
		rows[i].onmouseover = function(){
			previousClass = this.className;
			this.className = 'rowselected';
		};
		rows[i].onmouseout = function(){
			this.className = previousClass;
		};
	}
}